package test.udp;

import java.io.IOException;
import java.net.InetSocketAddress;

import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.transport.socket.nio.NioDatagramAcceptor;

public class UDPServer {

  private NioDatagramAcceptor acceptor;

  private static final int PORT=10000;

  private void start() {
    acceptor=new NioDatagramAcceptor();
    DefaultIoFilterChainBuilder chain=acceptor.getFilterChain();
    chain.addLast("log", new LoggingFilter());
    acceptor.setHandler(new UDPServerHandler());
    try {
      acceptor.bind(new InetSocketAddress(PORT));
      System.out.println("服务器启动完成!PORT=" + PORT);
    } catch(IOException e) {
      e.printStackTrace();
    }
  }

  public static void main(String[] args) {
    new UDPServer().start();
  }

  public void setAcceptor(NioDatagramAcceptor acceptor) {
    this.acceptor=acceptor;
  }

  public NioDatagramAcceptor getAcceptor() {
    return acceptor;
  }
}
